﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ExcelFileQueryTool
{
    public partial class frmClientLogDetail : Form
    {
        ExcelWorkLogItem _log;
        ExcelWorkLogService _svc;
        public frmClientLogDetail(ExcelWorkLogItem log, ExcelWorkLogService svc)
        {
            InitializeComponent();

            _log = log;
            _svc = svc;

            LoadData();
        }

        private void LoadData()
        {
            dtpDate.Value = _log.日期;
            cboxType.SelectedItem = _log.类型;
            txtName.Text = _log.客户供应商;
            txtProduct.Text = _log.货物;
            txtUnit.Text = _log.单位;
            numAmount.Value = _log.数量;
            numPrice.Value = _log.单价;
            numShippingFee.Value = _log.运装卸费;
            txtNote.Text = _log.备注;
            numPaidMoney.Value = _log.已收付货款;
            txtPayee.Text = _log.收付款人;
            txtShipping.Text = _log.运输方式;
        }

        private void btnCancle_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.Close();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            _log.日期 = dtpDate.Value;
            _log.类型 = cboxType.SelectedItem.ToString();
            _log.客户供应商 = txtName.Text;
            _log.货物 = txtProduct.Text;
            _log.单位 = txtUnit.Text;
            _log.数量 = numAmount.Value;
            _log.单价 = numPrice.Value;
            _log.运装卸费 = numShippingFee.Value;
            _log.备注 = txtNote.Text;
            _log.已收付货款 = numPaidMoney.Value;
            _log.收付款人 = txtPayee.Text;
            _log.运输方式 = txtShipping.Text;

            _svc.Save(_log);

            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.Close();
        }

        private void NumericControl_Leave(object sender, EventArgs e)
        {
            var control = (NumericUpDown)sender;

            if (string.IsNullOrWhiteSpace(control.Text))
                control.Value = 0m;
        }
    }
}
